|
|
|
|
|
|
|
Dim strLine As String
lstRecordset.Clear
'
rs.Index = strIndex
rs.MoveFirst
'
On Error Resume Next ' in case we get null fields
'
Do While Not rs.EOF
strLine = rs.Fields("Title")
strLine = strLine & " | " & CStr(rs.Fields("YearPub"))
strLine = strLine & " | " & CStr(rs.Fields("ISBN"))
strLine = strLine & " | " & CStr(rs.Fields("PubID"))
lstRecordset.AddItem strLine
rs.MoveNext
Loop
'
lblIndex.Caption = "Titles Table - Indexed by [" & strField & "]"
'
End Sub |
|
|
|
|
|
|
|
|
The LoadList procedure is an example of a way to load a Visual Basic list box with data from a table. The routine first clears out the list box. Then the Index property of the table object is set (based on the user's input) and moves to the first record in the table. |
|
|
|
|
|
|
|
|
Now the fun starts. The Do While..Loop construct reads each record in the table and creates a single line of text (strLine) that contains each of the fields separated by a single space. Notice that you need to use the CStr() function to convert the numeric fields in the data table (YearPub, ISBN, and Pub_ID) into string values before you can add them to strLine. After the line is built, the strLine is added to the list box using the lstRecordset.AddNew method. After the line is added to the list box, the record pointer is advanced using the rs.MoveNext method. This goes on until there are no more records in the table. |
|
|
|
|
|
|
|
|
The following three code segments go behind the appropriate command button to set the indexes. They set values for selecting the index, setting the display, and calling the routine to load the list box. |
|
|
|
|
|
|
|
|
Place this code in the cmdTitle_Click event: |
|
|
|
|
|
|
|
|
Private Sub cmdTitle_Click()
'
' set for Title index
'
strIndex = "Title"
strField = "Title"
LoadList
'
End Sub |
|
|
|
|
|